import {defineStore} from 'pinia'
import type {Source} from './interface/source'

export const useSource = defineStore('useSource',{
    state:():Source=>({
        //搜索历史
        searchHistory:localStorage.getItem('searchHistory')? JSON.parse(localStorage.getItem('searchHistory') as string):[],
        //全局loading加载
        vueElementLoading:false,
        //无限滚动禁止全局加载
        isEleLoading:false
    }),
    actions:{
    //    保存搜索历史
        setSearchHistory(search:string){
            if(this.searchHistory.includes(search))return
            this.searchHistory.unshift(search)
            localStorage.setItem('searchHistory',JSON.stringify(this.searchHistory))
        },
    //    改变loading状态
        changeLoading(bol:boolean){
            this.vueElementLoading = bol
        }
    }
})
